package com.amigo.online.provider.user.util;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.message.entity.MIMCJsonResponse;
import com.amigo.online.common.base.message.enums.MIMCUrlEnum;
import com.amigo.online.common.base.message.util.MIMCHttpUtil;
import com.amigo.online.common.base.security.LocalUser;
import com.amigo.online.common.param.result.LocalUserInfo;
import com.amigo.online.common.param.result.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

@Slf4j
public class IMBlackUtil {


    /**
     * 发送拉黑消息
     * @param userToken
     * @return
     */
    public static ResponseEntity<MIMCJsonResponse> addBlacklistMessage(String userId){
        Long uid = LocalUser.getUser().getUser().getId();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("blackAccount", userId);
        HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(jsonObject, MIMCHttpUtil.getUserHttpHeaders(uid.toString()));
        RestTemplate restTemplate =new RestTemplate();
        ResponseEntity<MIMCJsonResponse> responseEntity =  restTemplate.exchange(MIMCUrlEnum.ADD_BLACKLIST.getValue(), HttpMethod.POST, requestEntity , MIMCJsonResponse.class);
        log.debug("发送拉黑消息返回值: " + responseEntity.getBody());
        return responseEntity;
    }
    /**
     * 发送查看是否拉黑消息
     * @param userToken
     * @return
     */
    public static ResponseEntity<MIMCJsonResponse> selectBlacklistMessage(String userId){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("blackAccount", userId);
        HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(null, MIMCHttpUtil.getUserHttpHeaders());
        RestTemplate restTemplate =new RestTemplate();
        ResponseEntity<MIMCJsonResponse> responseEntity =  restTemplate.exchange(MIMCUrlEnum.SELECT_BLACKLIST.getValue()+userId, HttpMethod.GET, requestEntity , MIMCJsonResponse.class);
        log.debug("发送查看是否拉黑返回值: " + responseEntity.getBody());
        return responseEntity;
    }
    /**
     * 发送取消拉黑消息
     * @param userToken
     * @return
     */
    public static ResponseEntity<MIMCJsonResponse> deleteBlacklistMessage(String userId){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("blackAccount", userId);
        HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(null, MIMCHttpUtil.getUserHttpHeaders());
        RestTemplate restTemplate =new RestTemplate();
        ResponseEntity<MIMCJsonResponse> responseEntity =  restTemplate.exchange(MIMCUrlEnum.DELECT_BLACKLIST.getValue()+userId, HttpMethod.DELETE, requestEntity , MIMCJsonResponse.class);
        log.debug("解散群消息返回值: " + responseEntity.getBody());
        return responseEntity;
    }
    public static void main(String[] args) {

    }

}
